<?php

declare(strict_types=1);

namespace App\System\Database\Migrations;
use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateTenantTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('hei_tenant', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('租户信息表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('string', 'name', ['length' => 255, 'comment' => '租户名称']);
            $table->addColumn('string', 'code', ['length' => 100, 'comment' => '租户唯一编码，可用作内部标识符'])->nullable();
            $table->addColumn('text', 'description', ['length' => 1, 'comment' => '租户描述'])->nullable();
            $table->addColumn('smallInteger', 'status', ['default' => 1, 'comment' => '状态 (1正常 2停用)'])->nullable();
            $table->addColumn('smallInteger', 'sort', ['unsigned' => true, 'default' => 0, 'comment' => '排序'])->nullable();
            $table->addColumn('bigInteger', 'admin_id', ['comment' => '管理者ID'])->nullable();
            $table->addColumn('text', 'plan', ['length' => 1, 'comment' => '订阅计划'])->nullable();
            $table->addColumn('text', 'billing_info', ['length' => 1, 'comment' => '计费信息'])->nullable();
            $table->addColumn('text', 'custom_data', ['length' => 1, 'comment' => '自定义数据字段，用于存储租户特定的配置信息'])->nullable();
            $table->addColumn('bigInteger', 'created_by', ['comment' => '创建者'])->nullable();
            $table->addColumn('bigInteger', 'updated_by', ['comment' => '更新者'])->nullable();
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->addColumn('string', 'remark', ['length' => 255, 'comment' => '备注'])->nullable();
            $table->index('admin_id');
            $table->unique('code');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('hei_tenant');
    }
}
